package com.libaiwen.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.libaiwen.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
public class UserController {
	@RequestMapping(value = "/json1")
	@ResponseBody
	public List json1() throws JsonProcessingException {
		// ObjectMapper mapper = new ObjectMapper();
		// User user = new User("哈哈哈", 3, "男");
		// //将我们的对象解析成为json格式
		// String str = mapper.writeValueAsString(user);
		// // String str = mapper.writeValueAsString(books);

		List<User> books = new ArrayList<>();
		books.add(new User("哈哈哈", 3, "男"));

		return books;
	}
}
